<template>
  <div>
    <input type="text" v-model="username">
    <input type="password" v-model="password">

    <button @click="loginHandler">登录</button>
  </div>
</template>

<script>
export default {
  name: 'Login',
  data() {
    return {
      username: '',
      password: ''
    }
  },
  methods: {
    loginHandler() {
      this.$store
        .dispatch('userStore/login', {username: this.username, password: this.password})
        .then(() => {
          // 登陆成功后重定向
          this.$router.push({
            path: this.$route.query.redirect || '/home'
          })
        })
        .catch(err=>{
          console.log(err)
        })
    }
  }
}
</script>